using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


/// <summary>
/// This is the apprentice's aura. It appears around him and his casting circle. Initially, it will be sparkly white, but will
/// change to look more sinister as the apprentice's "evilness" increases.
/// </summary>

namespace DarkLordsApprenticeV2
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Aura : DrawableGameComponent
    {
        public Aura(Game game) : base(game){}

        public Vector2 Position { get; set; }   // position to draw on screen
        int animCounter;                        // step thru sprite sheet
        Texture2D image;                        // sprite sheet
        SpriteBatch spriteBatch;                // drawing interface
        Rectangle drawRect;                     // draw window on sprite sheet
        int drawSize;                           // square dimension of tiles in sprite sheet

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            Position = new Vector2(0, 0);
            animCounter = 0;
            image = Game.Content.Load<Texture2D>("aura");
            drawSize = 100;
            drawRect = new Rectangle(0, 0, drawSize, drawSize);
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            animCounter = (++animCounter % 16);
            drawRect.X = (animCounter % 4) * drawSize;
            drawRect.Y = ((animCounter - 1) / 4) * drawSize;

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            spriteBatch.Draw(
                image,
                Position,
                drawRect,   // rectangle 'window'
                Color.White,
                0.0f,
                Vector2.Zero,
                1.0f,
                SpriteEffects.None,
                0);
            spriteBatch.End();
        }
    }
}
